using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

using Volo.Abp.Account;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Identity;
using Volo.Abp.PermissionManagement;

using IdentityUser = Volo.Abp.Identity.IdentityUser;

namespace ApproveFlowEngine.Pages
{
    public class AccountModel : PageModel
    {
        private readonly IAccountAppService _accountAppService;
        private readonly IIdentityUserAppService _identityUserAppService;
        private readonly IPermissionManager _permissionManager;
        private readonly IIdentityUserRepository _identityUserRepository;

        public AccountModel(IAccountAppService accountAppService, IIdentityUserAppService identityUserAppService, IPermissionManager permissionManager, IIdentityUserRepository identityUserRepository)
        {
            _accountAppService = accountAppService;
            _identityUserAppService = identityUserAppService;
            _permissionManager = permissionManager;
            _identityUserRepository = identityUserRepository;
        }

        [BindProperty]
        public List<IdentityUser> Users { get; set; }

        public async Task<IActionResult> OnPostAsync()
        {
            return Page();
        }

        public async Task<IActionResult> OnGet()
        {
            var u = User;
            Users = await _identityUserRepository.GetListAsync();
            await _permissionManager.SetForUserAsync(Guid.Parse("3a13702b-c1c6-aec2-6870-472ef950baa7"), IdentityPermissions.Users.ManagePermissions, true);
            
            //IdentityPermissions.Users.Default
            //var temp=await _identityUserAppService.GetListAsync(new GetIdentityUsersInput());
            return Page();
        }
    }
}